<!-- 关闭Tab时顶部标题 -->
<div class="layui-body-header">
    <span class="layui-body-header-title">登录日志</span>
    <span class="layui-breadcrumb pull-right">
        <a href="#/">首页</a>
        <a><cite>登录日志</cite></a>
    </span>
</div>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">

            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">账号：</label>
                        <div class="layui-input-inline mr0">
                            <input id="lrEdtAccount" class="layui-input" type="text" placeholder="请输入账号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">日期：</label>
                        <div class="layui-input-inline mr0">
                            <input id="lrEdtDate" class="layui-input date-icon" type="text" placeholder="请选择日期范围"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="lrBtnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button id="lrBtnExp" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>导出</button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="logTable" lay-filter="logTable"></table>

        </div>
    </div>
</div>
<script>
    layui.use(['layer', 'laydate', 'table', 'util', 'http'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var table = layui.table;
        var util = layui.util;
        var laydate = layui.laydate;
        var http = layui.http;

        //渲染表格
        var ins1 = table.render({
            elem: '#logTable',
            url: http.base_server + 'login_record.json',
            where: {
                // access_token: http.getToken().access_token
            },
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'},
                {field: 'username', sort: true, title: '账号'},
                {field: 'nickName', sort: true, title: '用户名'},
                {field: 'ipAddress', sort: true, title: 'IP'},
                {field: 'device', sort: true, title: '设备'},
                {field: 'osName', sort: true, title: '设备类型'},
                {field: 'browserType', sort: true, title: '浏览器'},
                {
                    field: 'createTime', sort: true, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '登录时间'
                }
            ]]
        });

        //时间范围
        laydate.render({
            elem: '#lrEdtDate',
            type: 'date',
            range: true,
            theme: 'molv'
        });

        //搜索按钮点击事件
        $('#lrBtnSearch').click(function () {
            var searchDate = $('#lrEdtDate').val().split(' - ');
            var searchAccount = $('#lrEdtAccount').val();
            table.reload('logTable', {
                where: {
                    startDate: searchDate[0],
                    endDate: searchDate[1],
                    account: searchAccount
                }
            });
        });

        // 导出excel
        $('#lrBtnExp').click(function () {
            var checkRows = table.checkStatus('logTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(ins1.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>